﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Core.Base;
using Core;
using Components;

namespace MainApp.Modules.MainMenu
{
    public partial class MainScreen : SGVScreen
    {
        public MainScreen()
        {
            InitializeComponent();
            treeView1.ShowLines = false;
            treeView1.BackColor = Color.White;
            //treeView1.BackColor = Color.FromArgb(32, 85, 135);
            //treeView1.ForeColor = Color.White;
            this.Dock = DockStyle.Left;
            treeView1.KeyPress += new KeyPressEventHandler(treeView1_KeyPress);
            treeView1.ContextMenuStrip = new ContextMenuStrip();
            ToolStripMenuItem mnuExpandAll = new ToolStripMenuItem();
            mnuExpandAll.Text = "Expand All";
            mnuExpandAll.Click += new EventHandler(mnuExpandAll_Click);
            treeView1.ContextMenuStrip.Items.Add(mnuExpandAll);

            ToolStripMenuItem mnuCollapseAll = new ToolStripMenuItem();
            mnuCollapseAll.Text = "Collapse All";
            mnuCollapseAll.Click += new EventHandler(mnuCollapseAll_Click);
            treeView1.ContextMenuStrip.Items.Add(mnuCollapseAll);
            //treeView1.ShowRootLines = false;
            //treeView1.ShowPlusMinus = false;

        }

        void mnuCollapseAll_Click(object sender, EventArgs e)
        {
            treeView1.CollapseAll();
        }

        void mnuExpandAll_Click(object sender, EventArgs e)
        {
            treeView1.ExpandAll();
        }

        void treeView1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (treeView1.SelectedNode == null) return;
            if (treeView1.SelectedNode.Parent == null) return;

            if (e.KeyChar == (char)Keys.Enter)
            {
                if (treeView1.SelectedNode.Tag != null)
                {
                    String strModuleName = treeView1.SelectedNode.Tag.ToString();
                    BaseModule module = AppContext.CreateModule(strModuleName);
                    if (module != null)
                        module.Open(AppContext.MainAppForm);
                }
            }
        }

        private void MainScreen_Load(object sender, EventArgs e)
        {
               
            //treeView1.ExpandAll();
            treeView1.SelectedNode = treeView1.Nodes[0];
        }

        private void MainMenu_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node == null) return;
            if (e.Node.Parent == null) return;
            if (e.Node.Tag != null)
            {
                String strModuleName = e.Node.Tag.ToString();
                BaseModule module = AppContext.CreateModule(strModuleName);
                if (module != null)
                {
                    module.Open(AppContext.MainAppForm);
                }
            }
        }
    }
}
